home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / answrbok / 6_11.lha / 6_11 / 6_11.h < prev    next >
Text File  |  1993-08-08  |  2KB  |  93 lines

  1. * Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */
  2. * The C++ Answer Book */
  3. * Tony Hansen */
  4. * All rights reserved. */
  5. *
  6. arbitrary precision arithmetic
  7. Exercise 6.11
  8.  
  9.    All numbers are stored in an array of
  10.    unsigned shorts in two's complement format.
  11.    Its length is all maintained separately.
  12. /
  13. ifndef ARBINT_H
  14. define ARBINT_H
  15.  
  16.  include <stream.h>
  17.  include <minmax.h>
  18.  include <string.h>
  19.  include <error.h>
  20.  
  21. ypedef unsigned short ARB_type;
  22. ypedef unsigned long ARB_Ltype;
  23. onst ARB_Ltype ARB_base = 0x10000;
  24.  
  25. lass arbint
  26.  
  27.    struct arep
  28. {
  29. ARB_type *value;    // ptr to value
  30. int length;        // length of data
  31. int refcnt;        // reference count
  32. };
  33.  
  34.    arep *p;            // ptr to data
  35.  
  36.    arbint(ARB_type*,int);    /* DELETE */
  37.    friend void dodivmod(const arbint&,        /* DELETE */
  38. const arbint&, arbint&, arbint&);    /* DELETE */
  39. include "6_11a.h"        /* DELETE isneg() */
  40. include "6_11b.h"        /* DELETE arb_cmp() */
  41.  
  42. ublic:
  43.    arbint();                 // arbint x; or
  44.                  // new arbint;
  45.    ~arbint();                 // delete arbint;
  46.  
  47.    arbint(arbint&);             // arbint x = y;
  48.    arbint(long);             // arbint x = 35L;
  49.    arbint(unsigned long);         // arbint x = 35LU;
  50.    arbint(double);             // arbint x = 35.0;
  51.  
  52.    arbint& operator=(arbint&);         // x = y;
  53.    arbint& operator=(long);         // x = 35L;
  54.    arbint& operator=(unsigned long);// x = 35LU;
  55.    arbint& operator=(double);         // x = 35.0;
  56.  
  57.    friend arbint operator+
  58. (const arbint&, const arbint&);
  59.    friend arbint operator-
  60. (const arbint&, const arbint&);
  61.    friend arbint operator*
  62. (const arbint&, const arbint&);
  63.    friend arbint operator/
  64. (const arbint&, const arbint&);
  65.    friend arbint operator%
  66. (const arbint&, const arbint&);
  67.    friend arbint operator+
  68. (const arbint&);
  69.    friend arbint operator-
  70. (const arbint&);
  71.  
  72.    friend int operator==
  73. (const arbint&, const arbint&);
  74.    friend int operator!=
  75. (const arbint&, const arbint&);
  76.    friend int operator<
  77. (const arbint&, const arbint&);
  78.    friend int operator>=
  79. (const arbint&, const arbint&);
  80.    friend int operator>
  81. (const arbint&, const arbint&);
  82.    friend int operator<=
  83. (const arbint&, const arbint&);
  84.  
  85.    friend ostream& operator<<
  86. (ostream&, const arbint&);
  87.    friend istream& operator>>
  88. (istream&, arbint&);
  89. ;
  90.                                         // DELETE
  91. xtern void outputarb(ostream &out, char *h, ARB_type *s, int len, int ref = -100);    // DELETE
  92. endif /* ARBINT_H */
  93.